﻿namespace ServiceModelWebExample
{        
    using System;
    using System.Xml;
    using System.Collections.Generic;
    using System.ServiceModel.Syndication;
    using Chaliy.Syndication.MediaRss;

    class Program
    {
        static void Main(string[] args)
        {
            SyndicationFeed feed
                = new SyndicationFeed(BuildSyndicationItems());

            feed.Title = new TextSyndicationContent("SyndicationExt example feed.");
            feed.Authors.Add(new SyndicationPerson { Name = "Mike Chaliy", Email = "mike@chaliy.name" });

            Console.WriteLine("Example feed rendered with RSS formatter");
            using (XmlWriter writer = XmlWriter.Create(Console.Out))
            {                
                feed.SaveAsRss20(writer);                                
            }

            Console.WriteLine();
            Console.WriteLine("Example feed rendered with Atom formatter");
            using (XmlWriter writer = XmlWriter.Create(Console.Out))
            {
                feed.SaveAsAtom10(writer);
            }
        }

        private static IEnumerable<SyndicationItem> BuildSyndicationItems()
        {
            SyndicationItem item = new SyndicationItem();

            item.Title = new TextSyndicationContent("Item with content and thumbnail on the same flore.");
            item.ElementExtensions.Add(new MediaContent { Url = new Uri("http://www.foo.com/movie.mov"), Type = "video/quicktime" });
            item.ElementExtensions.Add(new MediaThumbnail { Url = new Uri("http://www.foo.com/movie-small.mov") });

            yield return item;


            SyndicationItem item2 = new SyndicationItem();

            item2.Title = new TextSyndicationContent("Item with content that includes thumbnail");
            MediaContent content2 
                = new MediaContent
                {
                    Url = new Uri("http://www.foo.com/movie.mov"),
                    Type = "video/quicktime" 
                };

            content2.ExtensionElements.Add(new MediaThumbnail { Url = new Uri("http://www.foo.com/movie-small.mov") });
            item2.ElementExtensions.Add(content2);

            yield return item2;
        }

    }
}
